package lims.client;


import javax.swing.JDialog;
import javax.swing.JFrame;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.Box;
import javax.swing.JPanel;

import java.awt.Component;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JPasswordField;

public class DialogLogin extends JDialog{
	
	public boolean okClicked=false;
	public String uid;
	public char[] pwd;
	
	public DialogLogin(JFrame owner) {
		super(owner);
		setResizable(false);
		setModal(true);
		setModalityType(ModalityType.APPLICATION_MODAL);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setTitle("登录");
		setSize(283, 212);
		setLocationRelativeTo(owner);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] {30, 0, 30, 0, 40};
		gridBagLayout.rowHeights = new int[] {30, 0, 30, 0, 30};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		getContentPane().setLayout(gridBagLayout);
		
		JLabel lblNewLabel = new JLabel("用户名:");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 1;
		gbc_lblNewLabel.gridy = 1;
		getContentPane().add(lblNewLabel, gbc_lblNewLabel);
		
		box_userName = new JTextField();
		GridBagConstraints gbc_box_userName = new GridBagConstraints();
		gbc_box_userName.insets = new Insets(0, 0, 5, 5);
		gbc_box_userName.fill = GridBagConstraints.HORIZONTAL;
		gbc_box_userName.gridx = 2;
		gbc_box_userName.gridy = 1;
		getContentPane().add(box_userName, gbc_box_userName);
		box_userName.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("密码:");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
		gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
		gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_1.gridx = 1;
		gbc_lblNewLabel_1.gridy = 3;
		getContentPane().add(lblNewLabel_1, gbc_lblNewLabel_1);
		
		box_password = new JPasswordField();
		GridBagConstraints gbc_box_password = new GridBagConstraints();
		gbc_box_password.insets = new Insets(0, 0, 5, 5);
		gbc_box_password.fill = GridBagConstraints.HORIZONTAL;
		gbc_box_password.gridx = 2;
		gbc_box_password.gridy = 3;
		getContentPane().add(box_password, gbc_box_password);
		
		JPanel panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.gridwidth = 5;
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 5;
		getContentPane().add(panel, gbc_panel);
		
		JButton btnNewButton = new JButton("确定");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				uid=box_userName.getText();
				pwd=box_password.getPassword();
				if(uid.trim().isEmpty()){
					JOptionPane.showMessageDialog(DialogLogin.this,"请输入用户名");
					return;
				}
				DialogLogin.this.okClicked=true;
				DialogLogin.this.dispose();
			}
		});
		panel.add(btnNewButton);
		getRootPane().setDefaultButton(btnNewButton);
		
		Component horizontalStrut = Box.createHorizontalStrut(40);
		panel.add(horizontalStrut);
		
		JButton btnNewButton_1 = new JButton("取消");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DialogLogin.this.dispose();
			}
		});
		panel.add(btnNewButton_1);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -7091818294366339362L;
	private JTextField box_userName;
	private JPasswordField box_password;

}
